package com.jt.web.controller;

import com.fasterxml.jackson.databind.util.JSONPObject;
import com.jt.config.CorsConfig;
import com.jt.pojo.ItemDesc;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class JSONPController {

    /**
     * 完成JSONP的调用
     * 规定：返回值结果，必须通过特殊格式封装.callback(json)
     * @return
     */
    @RequestMapping("/web/testJSONP")
    public JSONPObject jsonObject(String callback){
        ItemDesc itemDesc = new ItemDesc();
        itemDesc.setItemId(6666).setItemDesc("达内CGB");
        return new JSONPObject(callback,itemDesc);
    }

    /*public String jsonP(String callback){
        ItemDesc itemDesc = new ItemDesc();
        itemDesc.setItemId(6666).setItemDesc("达内CGB");
        String json = ObjectMapperUtil.toJson(itemDesc);
        return callback+json;
    }*/
}
